import sublemon from 'sublemon';

export const lcCode = {
	update: function (value) {
		var html = sublemon(value, {
		});

		this.el.innerHTML = html;
	}
};

// document.querySelectorAll and
// document.getElementsbyClassName will return
// a collection/list
// we will convert it to an array
// for easier assess
var toArray = function (nodeList) {
	return Array.prototype.slice.call(nodeList);
};

var selectByClass = function (el, selector) {
	return toArray(el.getElementsByClassName(selector));
};

export const lcCodeMark = {
	update: function (lineNum) {
		var lines = selectByClass(this.el, 'sublemon-view-line');
		var pos = lineNum - 1;

		// remove class from everything
		lines.forEach(function (el) {
			el.classList.remove('highlight');
		});
		// add class if pos > -1
		if (pos > -1 && lines[pos]) {
			lines[pos].classList.add('highlight');
		}
	}
};
